% read eyelink2 & matlab C data


clear
cd C:\_bcoe\EDF_Data\error_checked_data
files = dir('*C.mat'); % find all files with the eye extention
files.name;
for i=1:length(files)
    load(files(i).name)
    data(i)=C;
end

ang_ecc=[];
anti=[];
peri=[];
delay=[];
srt=[];
error=[];
long=[];
subject=[];
for i=1:length(files)
    ang_ecc=[ang_ecc; data(i).ang_ecc];
    anti=[anti; data(i).anti];
    peri=[peri; data(i).peri];
    delay=[delay; data(i).delay*1000];
    srt=[srt; data(i).srt'];
    error=[error; data(i).error'];
    long=[long; ((data(i).fix_on-data(i).iti)>5000)'];
    switch lower(files(i).name(12:14))
        case 'ahb', sub_code=1; 
        case 'bco', sub_code=2;
        case 'ian', sub_code=3;
        case 'jil', sub_code=4;
        case 'joe', sub_code=5;
        case 'kip', sub_code=6;
        case 'sue', sub_code=7;
    end          
    sub_text(sub_code,:)=lower(files(i).name(12:14))
    subject=[subject; (zeros(1,length(data(i).anti))+sub_code)'];    
end
%[(1:length(anti))' ang_ecc anti peri delay srt long] 
[subject long]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%population plots
fig(1);clf;
set(gcf,'name','Population Plots - Long v Short ITI','NumberTitle','off');

subplot(2,1,1);cla;hold on
h=scatter((delay(anti==0 & long==1 & error==0)/1000)-.05,srt(anti==0 & long==1 & error==0),'+')
set(h,'edgecolor',C.colors.PRO)
plot([0 .5  1]-.05,[mean(srt(anti==0 & long==1 & error==0 & delay==0)) mean(srt(anti==0 & long==1 & error==0 & delay==500)) mean(srt(anti==0 & long==1 & error==0 & delay==1000))],'color',C.colors.PRO) 
h=scatter((delay(anti==0 & long==0 & error==0)/1000)-.02,srt(anti==0 & long==0 & error==0))
set(h,'edgecolor',C.colors.PRO)
plot([0 .5  1]-.02,[mean(srt(anti==0 & long==0 & error==0 & delay==0)) mean(srt(anti==0 & long==0 & error==0 & delay==500)) mean(srt(anti==0 & long==0 & error==0 & delay==1000))],'-.','color',C.colors.PRO) 

h=scatter((delay(anti==1 & long==1 & error==0)/1000)+.05,srt(anti==1 & long==1 & error==0),'+')
set(h,'edgecolor',C.colors.ANTI)
plot([0 .5  1]+.05,[mean(srt(anti==1 & long==1 & error==0 & delay==0)) mean(srt(anti==1 & long==1 & error==0 & delay==500)) mean(srt(anti==0 & long==1 & error==0 & delay==1000))],'color',C.colors.ANTI) 
h=scatter((delay(anti==1 & long==0 & error==0)/1000)+.02,srt(anti==1 & long==0 & error==0))
set(h,'edgecolor',C.colors.ANTI)
plot([0 .5  1]+.02,[mean(srt(anti==1 & long==0 & error==0 & delay==0)) mean(srt(anti==1 & long==0 & error==0 & delay==500)) mean(srt(anti==0 & long==0 & error==0 & delay==1000))],'-.','color',C.colors.ANTI) 
ylabel('Saccadic Reaction Time')
xlabel('fixation to cue-tgt Delay')
set(gca,'XTick',[0 0.5 1])
tickout

subplot(2,2,3);cla;tickout;mann_whitney(srt(long==1),srt(long==0))
subplot(2,2,4);cla;tickout;  ttest_bcoe(srt(long==1),srt(long==0))
subplot(2,2,3);cla;tickout;mann_whitney(srt(long==1 & error==0),srt(long==0 & error==0))
subplot(2,2,4);cla;tickout;  ttest_bcoe(srt(long==1 & error==0),srt(long==0 & error==0))
ylabel('Count')
xlabel('Saccadic Reaction Time')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%subject plots

fig(2);clf;
set(gcf,'name','Subject Plots - Long v Short ITI','NumberTitle','off');

for i=1:length(sub_text)
    subplot(3,3,i),hold on,tickout
    title(upper(sub_text(i,:)));
    h=scatter((delay(anti==0 & long==1 & error==0 & subject==i)/1000)-.05,srt(anti==0 & long==1 & error==0 & subject==i),'+');
    set(h,'edgecolor',C.colors.PRO);
    plot([0 .5  1]-.05,[mean(srt(anti==0 & long==1 & error==0 & delay==0 & subject==i)) mean(srt(anti==0 & long==1 & error==0 & delay==500 & subject==i)) mean(srt(anti==0 & long==1 & error==0 & delay==1000 & subject==i))],'color',C.colors.PRO) ;
    h=scatter((delay(anti==0 & long==0 & error==0 & subject==i)/1000)-.02,srt(anti==0 & long==0 & error==0 & subject==i));
    set(h,'edgecolor',C.colors.PRO);
    plot([0 .5  1]-.02,[mean(srt(anti==0 & long==0 & error==0 & delay==0 & subject==i)) mean(srt(anti==0 & long==0 & error==0 & delay==500 & subject==i)) mean(srt(anti==0 & long==0 & error==0 & delay==1000 & subject==i))],'-.','color',C.colors.PRO); 
    
    h=scatter((delay(anti==1 & long==1 & error==0 & subject==i)/1000)+.05,srt(anti==1 & long==1 & error==0 & subject==i),'+');
    set(h,'edgecolor',C.colors.ANTI);
    plot([0 .5  1]+.05,[mean(srt(anti==1 & long==1 & error==0 & delay==0 & subject==i)) mean(srt(anti==1 & long==1 & error==0 & delay==500 & subject==i)) mean(srt(anti==0 & long==1 & error==0 & delay==1000 & subject==i))],'color',C.colors.ANTI) ;
    h=scatter((delay(anti==1 & long==0 & error==0 & subject==i)/1000)+.02,srt(anti==1 & long==0 & error==0 & subject==i));
    set(h,'edgecolor',C.colors.ANTI);
    plot([0 .5  1]+.02,[mean(srt(anti==1 & long==0 & error==0 & delay==0 & subject==i)) mean(srt(anti==1 & long==0 & error==0 & delay==500 & subject==i)) mean(srt(anti==0 & long==0 & error==0 & delay==1000 & subject==i))],'-.','color',C.colors.ANTI) ;
    ylabel('Saccadic Reaction Time');
    xlabel('fixation to cue-tgt Delay');
    set(gca,'XTick',[0 0.5 1]);   
end



fig(5);clf;hold on;tickout
subplot(2,2,1);cla;hold on;tickout

%subplot(3,1,1);hold on;tickout;title('pro v anti')
plot([0 .5  1],[mean(srt(error==0 & anti==0 & delay==0)) mean(srt(error==0 & anti==0 & delay==500)) mean(srt(error==0 & anti==0 & delay==1000))],'color',C.colors.PRO) 
plot([0 .5  1],[mean(srt(error==0 & anti==1 & delay==0)) mean(srt(error==0 & anti==1 & delay==500)) mean(srt(error==0 & anti==1 & delay==1000))],'color',C.colors.ANTI) 
%subplot(3,1,2);hold on;tickout;title('Peri v Fovial')
plot([0 .5  1],[mean(srt(error==0 & peri==0 & delay==0)) mean(srt(error==0 & peri==0 & delay==500)) mean(srt(error==0 & peri==0 & delay==1000))],'color',C.colors.BLACK) 
plot([0 .5  1],[mean(srt(error==0 & peri==1 & delay==0)) mean(srt(error==0 & peri==1 & delay==500)) mean(srt(error==0 & peri==1 & delay==1000))],'color',C.colors.M_GREY) 
%subplot(3,1,3);hold on;tickout;title('Long v Short')
plot([0 .5  1],[mean(srt(error==0 & long==0 & delay==0)) mean(srt(error==0 & long==0 & delay==500)) mean(srt(error==0 & long==0 & delay==1000))],'color',C.colors.CYAN) 
plot([0 .5  1],[mean(srt(error==0 & long==1 & delay==0)) mean(srt(error==0 & long==1 & delay==500)) mean(srt(error==0 & long==1 & delay==1000))],'color',C.colors.MAGENTA) 
h=text(0.8,780,'CENT');set(h,'color',C.colors.BLACK)
h=text(0.8,770,'SHORT');set(h,'color',C.colors.CYAN)
h=text(0.8,760,'ANTI');set(h,'color',C.colors.ANTI)
h=text(0.8,750,'PRO');set(h,'color',C.colors.PRO)
h=text(0.8,740,'LONG');set(h,'color',C.colors.MAGENTA)
h=text(0.8,730,'PERI');set(h,'color',C.colors.M_GREY)
ylim([600 800])
title('Overall Trends')
ylabel('Saccadic Reaction Time');
xlabel('fixation to cue-tgt Delay');
set(gca,'XTick',[0 0.5 1]);   


%fig(6);clf;hold on;tickout
subplot(2,2,2);cla;hold on;tickout
plot([0 .5  1],[mean(srt(error==0 & anti==1 & peri==0 & delay==0)) mean(srt(error==0 & anti==1 & peri==0 & delay==500)) mean(srt(error==0 & anti==1 & peri==0 & delay==1000))],'color',C.colors.BLACK) 
plot([0 .5  1],[mean(srt(error==0 & anti==1 & peri==1 & delay==0)) mean(srt(error==0 & anti==1 & peri==1 & delay==500)) mean(srt(error==0 & anti==1 & peri==1 & delay==1000))],'color',C.colors.M_GREY) 
plot([0 .5  1],[mean(srt(error==0 & anti==1 & long==0 & delay==0)) mean(srt(error==0 & anti==1 & long==0 & delay==500)) mean(srt(error==0 & anti==1 & long==0 & delay==1000))],'color',C.colors.CYAN) 
plot([0 .5  1],[mean(srt(error==0 & anti==1 & long==1 & delay==0)) mean(srt(error==0 & anti==1 & long==1 & delay==500)) mean(srt(error==0 & anti==1 & long==1 & delay==1000))],'color',C.colors.MAGENTA) 

plot([0 .5  1],[mean(srt(error==0 & anti==0 & peri==0 & delay==0)) mean(srt(error==0 & anti==0 & peri==0 & delay==500)) mean(srt(error==0 & anti==0 & peri==0 & delay==1000))],'--','color',C.colors.BLACK) 
plot([0 .5  1],[mean(srt(error==0 & anti==0 & peri==1 & delay==0)) mean(srt(error==0 & anti==0 & peri==1 & delay==500)) mean(srt(error==0 & anti==0 & peri==1 & delay==1000))],'--','color',C.colors.M_GREY) 
plot([0 .5  1],[mean(srt(error==0 & anti==0 & long==0 & delay==0)) mean(srt(error==0 & anti==0 & long==0 & delay==500)) mean(srt(error==0 & anti==0 & long==0 & delay==1000))],'--','color',C.colors.CYAN) 
plot([0 .5  1],[mean(srt(error==0 & anti==0 & long==1 & delay==0)) mean(srt(error==0 & anti==0 & long==1 & delay==500)) mean(srt(error==0 & anti==0 & long==1 & delay==1000))],'--','color',C.colors.MAGENTA) 
h=text(0.8,780,'CENT');set(h,'color',C.colors.BLACK)
h=text(0.8,770,'SHORT');set(h,'color',C.colors.CYAN)
%h=text(0.8,760,'ANTI');set(h,'color',C.colors.ANTI)
%h=text(0.8,750,'PRO');set(h,'color',C.colors.PRO)
h=text(0.8,740,'LONG');set(h,'color',C.colors.MAGENTA)
h=text(0.8,730,'PERI');set(h,'color',C.colors.M_GREY)
ylim([600 800])
title('ANTI(-) v PRO(--) Trends')
ylabel('Saccadic Reaction Time');
xlabel('fixation to cue-tgt Delay');
set(gca,'XTick',[0 0.5 1]);   

subplot(2,2,3);cla;hold on;tickout
plot([0 .5  1],[mean(srt(error==0 & peri==1 & anti==0 & delay==0)) mean(srt(error==0 & peri==1 & anti==0 & delay==500)) mean(srt(error==0 & peri==1 & anti==0 & delay==1000))],'color',C.colors.PRO) 
plot([0 .5  1],[mean(srt(error==0 & peri==1 & anti==1 & delay==0)) mean(srt(error==0 & peri==1 & anti==1 & delay==500)) mean(srt(error==0 & peri==1 & anti==1 & delay==1000))],'color',C.colors.ANTI) 
plot([0 .5  1],[mean(srt(error==0 & peri==1 & long==0 & delay==0)) mean(srt(error==0 & peri==1 & long==0 & delay==500)) mean(srt(error==0 & peri==1 & long==0 & delay==1000))],'color',C.colors.CYAN) 
plot([0 .5  1],[mean(srt(error==0 & peri==1 & long==1 & delay==0)) mean(srt(error==0 & peri==1 & long==1 & delay==500)) mean(srt(error==0 & peri==1 & long==1 & delay==1000))],'color',C.colors.MAGENTA) 

plot([0 .5  1],[mean(srt(error==0 & peri==0 & anti==0 & delay==0)) mean(srt(error==0 & peri==0 & anti==0 & delay==500)) mean(srt(error==0 & peri==0 & anti==0 & delay==1000))],'--','color',C.colors.PRO) 
plot([0 .5  1],[mean(srt(error==0 & peri==0 & anti==1 & delay==0)) mean(srt(error==0 & peri==0 & anti==1 & delay==500)) mean(srt(error==0 & peri==0 & anti==1 & delay==1000))],'--','color',C.colors.ANTI) 
plot([0 .5  1],[mean(srt(error==0 & peri==0 & long==0 & delay==0)) mean(srt(error==0 & peri==0 & long==0 & delay==500)) mean(srt(error==0 & peri==0 & long==0 & delay==1000))],'--','color',C.colors.CYAN) 
plot([0 .5  1],[mean(srt(error==0 & peri==0 & long==1 & delay==0)) mean(srt(error==0 & peri==0 & long==1 & delay==500)) mean(srt(error==0 & peri==0 & long==1 & delay==1000))],'--','color',C.colors.MAGENTA) 
%h=text(0.8,780,'CENT');set(h,'color',C.colors.BLACK)
h=text(0.8,770,'SHORT');set(h,'color',C.colors.CYAN)
h=text(0.8,760,'ANTI');set(h,'color',C.colors.ANTI)
h=text(0.8,750,'PRO');set(h,'color',C.colors.PRO)
h=text(0.8,740,'LONG');set(h,'color',C.colors.MAGENTA)
%h=text(0.8,730,'PERI');set(h,'color',C.colors.M_GREY)
ylim([600 800])
title('PERI(-) v CENT(--) Trends')
ylabel('Saccadic Reaction Time');
xlabel('fixation to cue-tgt Delay');
set(gca,'XTick',[0 0.5 1]);  

subplot(2,2,4);cla;hold on;tickout
plot([0 .5  1],[mean(srt(error==0 & long==1 & anti==0 & delay==0)) mean(srt(error==0 & long==1 & anti==0 & delay==500)) mean(srt(error==0 & long==1 & anti==0 & delay==1000))],'color',C.colors.PRO) 
plot([0 .5  1],[mean(srt(error==0 & long==1 & anti==1 & delay==0)) mean(srt(error==0 & long==1 & anti==1 & delay==500)) mean(srt(error==0 & long==1 & anti==1 & delay==1000))],'color',C.colors.ANTI) 
plot([0 .5  1],[mean(srt(error==0 & long==1 & peri==0 & delay==0)) mean(srt(error==0 & long==1 & peri==0 & delay==500)) mean(srt(error==0 & long==1 & peri==0 & delay==1000))],'color',C.colors.BLACK) 
plot([0 .5  1],[mean(srt(error==0 & long==1 & peri==1 & delay==0)) mean(srt(error==0 & long==1 & peri==1 & delay==500)) mean(srt(error==0 & long==1 & peri==1 & delay==1000))],'color',C.colors.M_GREY) 

plot([0 .5  1],[mean(srt(error==0 & long==0 & anti==0 & delay==0)) mean(srt(error==0 & long==0 & anti==0 & delay==500)) mean(srt(error==0 & long==0 & anti==0 & delay==1000))],'--','color',C.colors.PRO) 
plot([0 .5  1],[mean(srt(error==0 & long==0 & anti==1 & delay==0)) mean(srt(error==0 & long==0 & anti==1 & delay==500)) mean(srt(error==0 & long==0 & anti==1 & delay==1000))],'--','color',C.colors.ANTI) 
plot([0 .5  1],[mean(srt(error==0 & long==0 & peri==0 & delay==0)) mean(srt(error==0 & long==0 & peri==0 & delay==500)) mean(srt(error==0 & long==0 & peri==0 & delay==1000))],'--','color',C.colors.BLACK) 
plot([0 .5  1],[mean(srt(error==0 & long==0 & peri==1 & delay==0)) mean(srt(error==0 & long==0 & peri==1 & delay==500)) mean(srt(error==0 & long==0 & peri==1 & delay==1000))],'--','color',C.colors.M_GREY) 
h=text(0.8,780,'CENT');set(h,'color',C.colors.BLACK)
%h=text(0.8,770,'SHORT');set(h,'color',C.colors.CYAN)
h=text(0.8,760,'ANTI');set(h,'color',C.colors.ANTI)
h=text(0.8,750,'PRO');set(h,'color',C.colors.PRO)
%h=text(0.8,740,'LONG');set(h,'color',C.colors.MAGENTA)
h=text(0.8,730,'PERI');set(h,'color',C.colors.M_GREY)
ylim([600 800])
title('LONG(-) v SHORT(--) Trends')
ylabel('Saccadic Reaction Time');
xlabel('fixation to cue-tgt Delay');
set(gca,'XTick',[0 0.5 1]);  